<?php

namespace App\Models\Traits;

use App\Models\Scopes\UserScope;
use Illuminate\Database\Eloquent\Model;

trait HasUserScope
{
    public static function bootHasUserScope()
    {
        static::addGlobalScope(new UserScope());
        static::creating(function(Model $model){
            if (auth('user')->check()) {
                $admin = auth('user')->user();
                $model->setAttribute('user_id', $admin->client_id);
            }
        });
    }

    public function user()
    {
        return $this->belongsTo(User::class);
    }
}
